package com.xuanxing123.model;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import javax.persistence.*;
import static javax.persistence.GenerationType.IDENTITY;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

@Entity
@Table(name="agent",catalog="xuanxing")
@Searchable
@XmlRootElement
public class Agent extends BaseObject implements Serializable {
    private Long id;
    private Product product;
    private String name;
    private String description;
    private String companyType;
    private String comments;
    private String website;
    private String phone;
    private String logo;
    private Integer position;

    @Id @GeneratedValue(strategy=IDENTITY)
    @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="product_id", nullable=false)
    public Product getProduct() {
        return this.product;
    }
    
    public void setProduct(Product product) {
        this.product = product;
    }
    
    @Column(name="name", nullable=false, length=100)
    @SearchableProperty
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="description", length=254)
    @SearchableProperty
    public String getDescription() {
        return this.description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    @Column(name="company_type", length=10)
    @SearchableProperty
    public String getCompanyType() {
        return this.companyType;
    }
    
    public void setCompanyType(String companyType) {
        this.companyType = companyType;
    }
    
    @Column(name="comments", length=254)
    @SearchableProperty
    public String getComments() {
        return this.comments;
    }
    
    public void setComments(String comments) {
        this.comments = comments;
    }
    
    @Column(name="website", length=100)
    @SearchableProperty
    public String getWebsite() {
        return this.website;
    }
    
    public void setWebsite(String website) {
        this.website = website;
    }
    
    @Column(name="phone", length=50)
    @SearchableProperty
    public String getPhone() {
        return this.phone;
    }
    
    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    @Column(name="logo", length=254)
    @SearchableProperty
    public String getLogo() {
        return this.logo;
    }
    
    public void setLogo(String logo) {
        this.logo = logo;
    }
    
    @Column(name="position", nullable=false)
    @SearchableProperty
    public Integer getPosition() {
        return this.position;
    }
    
    public void setPosition(Integer position) {
        this.position = position;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Agent pojo = (Agent) o;

        if (product != null ? !product.equals(pojo.product) : pojo.product != null) return false;
        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
        if (description != null ? !description.equals(pojo.description) : pojo.description != null) return false;
        if (companyType != null ? !companyType.equals(pojo.companyType) : pojo.companyType != null) return false;
        if (comments != null ? !comments.equals(pojo.comments) : pojo.comments != null) return false;
        if (website != null ? !website.equals(pojo.website) : pojo.website != null) return false;
        if (phone != null ? !phone.equals(pojo.phone) : pojo.phone != null) return false;
        if (logo != null ? !logo.equals(pojo.logo) : pojo.logo != null) return false;
        if (position != null ? !position.equals(pojo.position) : pojo.position != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (product != null ? product.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (companyType != null ? companyType.hashCode() : 0);
        result = 31 * result + (comments != null ? comments.hashCode() : 0);
        result = 31 * result + (website != null ? website.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (logo != null ? logo.hashCode() : 0);
        result = 31 * result + (position != null ? position.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("product").append("='").append(getProduct()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("description").append("='").append(getDescription()).append("', ");
        sb.append("companyType").append("='").append(getCompanyType()).append("', ");
        sb.append("comments").append("='").append(getComments()).append("', ");
        sb.append("website").append("='").append(getWebsite()).append("', ");
        sb.append("phone").append("='").append(getPhone()).append("', ");
        sb.append("logo").append("='").append(getLogo()).append("', ");
        sb.append("position").append("='").append(getPosition()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
